/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package factory2;

import java.util.ArrayList;

/**
 *
 * @author wida46984148
 */
public class Shocks {
    boolean surt = false;
    int cnt = 0;    //disparos acertados    cosas de pol (8)
    int cnt1 = 0;   //disparos enemigo0
    int cnt2 = 0;   //disparos enemigo1
    int cnt3 = 0;   //disparos enemigo2
    int cntTT = 0;
    public void shocksControl(ArrayList<Shoot> shootEnemig, ArrayList<NauEnemiga> nauEnemig,
            ArrayList<NauBase> NauW, ArrayList<Shoot> shootW) {
        try {
            //nau-W vs nau-enemiga
            for (Object ob1 : nauEnemig) {
                NauEnemiga nb1 = (NauEnemiga) ob1;
                for (Object ob2 : NauW) {
                    NauBase nb2 = (NauBase) ob2;
                    if (nb1.collideWith(nb2.getShape()) && nb1.posY <= nb2.posY) {
                        //nb1.destroy = true;
                        nb2.destroy = true;
                        nauEnemig.remove(nb1);
                    }
                }
            }

            //shoot-W vs nau-enemig

            for (Object ob1 : nauEnemig) {
                NauEnemiga nb1 = (NauEnemiga) ob1;
                for (Object ob2 : shootW) {
                    Shoot st = (Shoot) ob2;
                    if (nb1.collideWith(st.getShape()) && nb1.posY <= st.posY ) {
                        nb1.impacte(st.getDany());
                        //nb1.destroy = true;
                        cnt++;
                        st.destroy = true;
                        shootW.remove(st);
//                        System.out.println("disparo acertado = " + cnt);
                        if(nb1.isMort()){
                            if(nb1 instanceof NauEnemiga0){
                                cnt1++;
//                                System.out.println("NauEnemiga0 destruidas :" + cnt1);
                            } else if (nb1 instanceof NauEnemiga1){
                                cnt2++;
//                                System.out.println("NauEnemiga2 destruidas :" + cnt2);
                            } else if (nb1 instanceof NauEnemiga2){
                                cnt3++;
//                                System.out.println("NauEnemiga2 destruidas :" + cnt3);
                            }
                            cntTT = cnt+cnt1+cnt2+cnt3;
//                            System.out.println("total de naves destruidas: " + cntTT);
                        }
                    }
                }
            }


            //nau-W vs shoot-enemig
            for (Object ob2 : shootEnemig) {
                Shoot st2 = (Shoot) ob2;
                for (Object ob1 : NauW) {
                    NauBase nb1 = (NauBase) ob1;
                    if (nb1.collideWith(st2.getShape()) && st2.posY <= nb1.posY) {
                        nb1.impacte(st2.getDany());
                        st2.destroy = true;
                        //shootEnemig.remove(st2);
                    }
                }
            }
        } catch (Exception e) {
        }

    }
}
